<?php
namespace Componentes\Controller;

use Componentes\Controller\RestfulController;

class GenericController extends RestfulController {

    public function bd() {
        return $this->getServiceLocator()->get('Zend\Db\Adapter');
    }

    /**
     * @return type response
     */
    public function getResponseWithHeader() {
        $response = $this->getResponse();
        $response->getHeaders()
                //make can accessed by *  
                ->addHeaderLine('Access-Control-Allow-Origin', '*')
                //set allow methods
                ->addHeaderLine('Access-Control-Allow-Methods', 'POST PUT DELETE GET');
        return $response;
    }

    public function convertirArrayAJson($array) {
        $registro_json = \Zend\Json\Json::encode($array, true);
        $response = $this->getResponseWithHeader();
        $response->getHeaders()->addHeaders(array(
            'Content-Type' => 'application/json',)
        );
        $response->setContent($registro_json);
        return $response;
    }

}
